﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using kxcxw.Data.Common;
using kxcxw.Data;
using Webdiyer.WebControls.Mvc;
using kxcxw.Data.Entities;
using System.Data;

namespace KXCXW.Web.Areas.Admin.Controllers
{
    /// <summary>
    /// 反馈信息
    /// </summary>
    public class FeedbackController : Controller
    {
        private KXCXWDBContext db = new KXCXWDBContext();

        //
        // GET: /Admin/Feedback/

        [Authorize(Roles = DataConstants.Admin)]
        public ActionResult Index(string sortOrder, string searchString, int? page = 1)
        {
            var feedbacks = from s in db.Feedbacks select s;

            int pageSize = 15;
            int pageIndex = page ?? 1;
            feedbacks = feedbacks.OrderByDescending(t => t.CreateDate);
            PagedList<Feedback> temp = feedbacks.ToPagedList(pageIndex, pageSize);
            if (Request.IsAjaxRequest())
                return PartialView("List", temp);
            return View(temp);
        }

        [Authorize(Roles = DataConstants.Admin)]
        public ViewResult Details(long id)
        {
            Feedback fb = db.Feedbacks.Find(id);

            return View(fb);
        }

        [Authorize(Roles = DataConstants.Admin)]
        public ActionResult Edit(long id)
        {
            Feedback fb = db.Feedbacks.Find(id);


            return View(fb);
        }

        //
        // POST: /Info/Edit/5
        [Authorize(Roles = DataConstants.Admin)]
        [HttpPost]
        public ActionResult Edit(PublichInformation fb)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(fb).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                }
            }
            return View(fb);
        }

        //[Authorize(Roles = DataConstants.Admin)]
        public JsonResult Delete(long id)
        {
            Feedback fb = db.Feedbacks.Find(id);
            db.Feedbacks.Remove(fb);
            db.SaveChanges();//string sortOrder, string searchString, int? page = 1
            return Json(new { status = true }, JsonRequestBehavior.AllowGet);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

    }//class
}